﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using Hawaii.Services.Client;
using Hawaii.Services.Client.Relay;
using Convo.POCOs;
using ServiceMessages.ResponsePOCOs;


namespace Convo
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        private ConvoClient client;
        public MainPage()
        {
            InitializeComponent();
            client = new ConvoClient("http://127.0.0.1:81/Service1.svc");
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

            this.textBox1.Text = (App.Current as App).User.FirstName;
            this.textBox2.Text = (App.Current as App).User.Status;
            this.textBox4.Text = (App.Current as App).RelayContext.Endpoint.RegistrationId;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var request = client.setupChatRequest("1");

            client.ExecuteAsync<SetupChatResponse>(request, (response) =>
            {
                
                if (response.StatusCode == HttpStatusCode.OK && response.Data != null)
                {
                    (App.Current as App).ConvContext = new ConvId { Endpoint = response.Data.Endpoint, FriendId = "1" };
                }
            });
            
            this.NavigationService.Navigate(new Uri("/ChatPage.xaml",UriKind.Relative));
         }

    }
}